const name: "why" = "why";
let age: 18 = 18;

//将多个字面量类型联合起来
type Direaction = "left" | "right" | "up" | "down";

//这可值只能限制上面的几个
const d1: Direaction = "right";

//列子：请求方法时
type methodType = "get" | "post";
function request(url: string, method: methodType) {}
request("http://baidu.com", "post");

//问题1：
const info = {
  url: "xxx",
  method: "post",
};

//这种传值是错误的，info.method获取的是string类型
// request(info.url, info.method);

//解决方法1：info.method进行类型断言
request(info.url, info.method as "post");

//直接让info对象是一个字面量类型后面加一个as const
const info2 = {
  url: "xxxx",
  method: "post",
} as const;
request(info.url, info.method as "post");

export {};
